#!/bin/sh
#
# Run a simple backup but
#   split the archive into two volumes, then restore
#   files on only one of the volumes and ensure that
#   the other volume is not used.  I.e. bsr optimization
#   works.
#
TestName="bsr-opt-test"
JobName=bsr-opt
. scripts/functions

scripts/cleanup
scripts/copy-test-confs
change_jobname NightlySave $JobName

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${tmp}/log1.out
label storage=File1 volume=TestVolume001
label storage=File1 volume=TestVolume002
update Volume=TestVolume001 MaxVolBytes=10000
run job=$JobName storage=File1 yes
wait
messages
@#
@# now do a restore
@#
@$out ${tmp}/log2.out
setdebug level=150 storage=File1
restore bootstrap=${working}/restore.bsr where=${tmp}/susan-restores select storage=File1
unmark *
cd ${BackupDirectory}
mark *
ls
done
yes
wait
messages
quit
END_OF_DATA

run_susan
check_for_zombie_jobs storage=File1
stop_susan
#
# This test is not really reliable. What we want to do is
#   to select files on only one Volume, then insure here
#   that only one Volume is chosen.
#
grep TestVolume002 ${working}/restore.bsr 2>&1 >/dev/null
bsrstat=$?
if [ $bsrstat != 0 ]; then
   echo "  !!!!! Volume selection error         !!!!! "
   echo "  !!!!! Volume selection error         !!!!! " >>test.out
fi

check_two_logs

check_restore_diff

# end tests and check for error codes
end_test

